#include "Ctrl.h"

#if PrototypePattern_

//抽象原型类
class Dog
{
public:
	virtual ~Dog() {}
	virtual Dog* clone() = 0;	//克隆方法
	virtual void play() = 0;	//其他公共接口
};

//具体原型类
class Twoha :public Dog
{
public:
	Twoha(string name)
		:name{ name } {}
	//拷贝构造函数（深拷贝）
	Twoha(const Twoha& lhs)
	{
		//存在指针则必须使用深拷贝
		name = lhs.name;
	}
	//实现抽象方法
	Dog* clone()
	{
		return new Twoha{ *this };
	}
	void play()
	{
		cout << "我是一只" << name << endl;
	}
private:
	string name;
};
int main()
{
	Dog* dog = new Twoha{ "二哈" };
	Dog* Eha1 = dog->clone();
	Dog* Eha2 = dog->clone();
	Eha1->play();
	Eha2->play();

	delete dog;
	delete Eha1;
	delete Eha2;
	return 0;
}

#endif